package udp;

import java.io.*;
import java.net.*;

public class Server {

	private static String[] categories = { "1. Structure", "2. Object",
			"3. Logic", "4. Class" };

	public static void main(String args[]) throws Exception {

		DatagramSocket serverSocket = new DatagramSocket(9876);
		byte[] receiveData = new byte[1024];
		byte[] sendData = new byte[1024];

		while (true) {
			DatagramPacket receivePacket = new DatagramPacket(receiveData,
					receiveData.length);
			serverSocket.receive(receivePacket);

			InetAddress IPAddress = receivePacket.getAddress();
			int port = receivePacket.getPort();

			String cmd = new String(receivePacket.getData());

			if (cmd.equals("Start")) {
				for (int i = 0; i < categories.length; i++) {
					sendData = categories[i].getBytes();
					DatagramPacket sendPacket = new DatagramPacket(sendData,
							sendData.length, IPAddress, port);
					serverSocket.send(sendPacket);
				}
			}
		}
	}
}